<?php

# -- DÉBUT NOTE DE LICENCE -------------------------------------
#
# Ce fichier fait partie de Clicpage.
#
# Copyright (c) 2010 Francois (www.clicpage.net)
# Distribué selon les termes de la licence GPL version 2.0.
# Consultez le fichier LICENCE ou
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- FIN NOTE DE LICENCE ---------------------------------------

require(dirname(__FILE__).'/_prepend.php');
require(CP_CLASS_FOLDER.'/admin/prepend.php');

$scripts = preg_replace( '/[^a-z0-9,_-]+/i', '', $_GET['scripts'] );
$scripts = explode(',', $scripts);

if ( empty($scripts) ) {
	exit;
}

$compress = ( isset($_GET['c']) && $_GET['c'] );
$force_gzip = ( $compress && 'gzip' == $_GET['c'] );
$expires_offset = 31536000;
$out = '';

foreach( $scripts as $script ) {
	# --COMPORTEMENT-- adminJavascript
	$out .= $core->executerComportement('adminJavascript', $script)."\n";
}

header('Content-Type: application/x-javascript; charset=UTF-8');
header('Expires: '.strftime('%a, %d %b %Y %H:%M:%S', (time() + $expires_offset)).' GMT');
header('Cache-Control: public, max-age='.$expires_offset);
header('Pragma: public');


if ( $compress && ! ini_get('zlib.output_compression') && 'ob_gzhandler' != ini_get('output_handler') ) {
	header('Vary: Accept-Encoding'); // Handle proxies
	if ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) {
		header('Content-Encoding: deflate');
		$out = gzdeflate( $out, 3 );
	} elseif ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') && function_exists('gzencode') ) {
		header('Content-Encoding: gzip');
		$out = gzencode( $out, 3 );
	}
}

echo $out;
exit;

?>